<template>
  <div id="detail-nav-bar">
    <nav-bar>
      <template v-slot:left >
        <div class="back-img" @click="backClick">
          <img src="~assets/img/common/back.svg" alt="">
        </div>
      </template>
      <template v-slot:center>
        <div class="title">
          <div v-for="(item, index) in titles"
               :key="index"
               class="title-item"
               :class="{active:currentIndex === index}"
               @click="titleClick(index)">
            {{ item }}
          </div>
        </div>
      </template>
    </nav-bar>
  </div>
</template>

<script>
  import NavBar from "@/components/common/navbar/NavBar";
  export default {
    name: "DetailNavBar",
    components:{
      NavBar,
    },
    data(){
      return {
        titles:['商品','参数','评论','推荐'],
        currentIndex:0
      }
    },
    methods:{
      backClick(){
        this.$router.back()
      },
      titleClick(index){
        this.currentIndex = index
        this.$emit('titleClick',index)
      }
    }
  }
</script>

<style scoped>
  #detail-nav-bar{
    font-size: 14px;
    /*background-color: #50b7c1;*/
  }
  .back-img img{
    width:30%;
    margin-top: 13px;
  }
  .title{
    display: flex;
  }
  .title-item{
    flex: 1;
    color: #666666;
  }
  .active{
    color: #50b7c1;
  }
</style>